/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.util.FormUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.JMenuItem;
import model.Conection;
import model.Dokument;
import model.Dosen;
import model.Surat;
import view.PanelLihatTabelDokument;

/**
 *
 * @author priska
 */
public class FrameUtamaSekretariat extends JFrame {

    public static void main(String[] args) {
        FrameUtamaSekretariat f = new FrameUtamaSekretariat();
    }
    private JMenuBar menuBar;
    private JMenu Surat;
    private JMenu Dokument, tabell, dosen;
    private JMenuItem BuatSurat, ceksurat, cekdokument, cekdosen;
    private JLabel gambar;
    private JMenuItem BuatDokument, buatTabel, hapusTabel, addDosen, remDosen;

    public FrameUtamaSekretariat() {
        this.setSize(516, 550);
        FormUtil.centerWindow(this);
        this.setLayout(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        this.setTitle(" Frame Sekretariat ");

        menuBar = new JMenuBar();
        setJMenuBar(menuBar);


        Surat = new JMenu(" SURAT ");
        menuBar.add(Surat);

        Dokument = new JMenu(" DOKUMENT ");
        menuBar.add(Dokument);

        ceksurat = new JMenuItem("Cek Surat");
        Surat.add(ceksurat);
        ceksurat.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tampilSur();
                JFrame fr = new JFrame();
                PanelCekSurat pan = new PanelCekSurat(surat);
                fr.getContentPane().add(pan);
                FormUtil.setMaximize(fr);
                fr.setVisible(true);

            }
            private ArrayList<Surat> surat;

            private void tampilSur() {
                surat = new ArrayList<Surat>();
                Connection con = Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
                Statement stat = null;
                try {
                    stat = con.createStatement();
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaDosen.class.getName()).log(Level.SEVERE, null, ex);
                }
                String sql = "select * from SURAT";
                ResultSet res = null;
                try {
                    res = stat.executeQuery(sql);
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaDosen.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    while (res.next()) {
                        Surat sur = new Surat();
                        sur.setNomorSurat(res.getString("NO_SURAT"));
                        sur.setPerihal(res.getString("PERIHAL"));
                        sur.setAsalSurat(res.getString("ASAL_SURAT"));
                        sur.setPenerimaSurat(res.getString("PENERIMA"));
                        sur.setLetakSurat(res.getString("LETAK_SURAT"));
                        sur.setPetugasPenerimaSurat(res.getString("PETUGAS_PENERIMA_SURAT"));
                        sur.setTanggal(res.getString("TANGGAL"));
                        sur.setKeterangan(res.getString("KETERANGAN"));
                        surat.add(sur);
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaDosen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });

        cekdokument = new JMenuItem("Cek Document");
        Dokument.add(cekdokument);
        cekdokument.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tampilDoc();
                JFrame fr = new JFrame();
                PanelCekDokumen pan = new PanelCekDokumen(dokument);
                fr.getContentPane().add(pan);
                FormUtil.setMaximize(fr);
                fr.setVisible(true);
            }
            private ArrayList<Dokument> dokument;

            private void tampilDoc() {
                dokument = new ArrayList<>();
                Connection con = Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
                Statement stat = null;
                try {
                    stat = con.createStatement();
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaSekretariat.class.getName()).log(Level.SEVERE, null, ex);
                }
                String tampildok = " SELECT * FROM DOKUMEN ";
                ResultSet td = null;
                try {
                    td = stat.executeQuery(tampildok);
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaSekretariat.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    while (td.next()) {
                        Dokument doc = new Dokument();
                        doc.setNoDokument(td.getString("NO_DOKUMEN"));
                        doc.setPerihal(td.getString("PERIHAL"));
                        doc.setAsalDokument(td.getString("ASAL_DOKUMEN"));
                        doc.setPenerimaDokument(td.getString("PENERIMA"));
                        doc.setLetakDokument(td.getString("LETAK_DOKUMEN"));
                        doc.setPetugasPenerimaDokument(td.getString("PETUGAS_PENERIMA_DOKUMEN"));
                        doc.setTanggal(td.getString("TANGGAL"));
                        doc.setKeterangan(td.getString("KETERANGAN"));
                        dokument.add(doc);
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaSekretariat.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        BuatSurat = new JMenuItem(" Masukan Data Surat");
        Surat.add(BuatSurat);
        BuatSurat.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                FormTambahSurat fs = new FormTambahSurat();
            }
        });

        BuatDokument = new JMenuItem(" Masukkan Data Dokument ");
        Dokument.add(BuatDokument);
        BuatDokument.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                FormDokument fd = new FormDokument();
            }
        });

        dosen = new JMenu("DOSEN");
        menuBar.add(dosen);

        cekdosen = new JMenuItem("Cek Daftar Dosen");
        dosen.add(cekdosen);

        cekdosen.addActionListener(new ActionListener() {
            private ArrayList<Dosen> dosen;

            @Override
            public void actionPerformed(ActionEvent e) {
                dosen = new ArrayList<>();
                Connection con = Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
                Statement stat = null;
                try {
                    stat = con.createStatement();
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaSekretariat.class.getName()).log(Level.SEVERE, null, ex);
                }
                String sql = "select * from dosen";
                ResultSet res = null;
                try {
                    res = stat.executeQuery(sql);
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaSekretariat.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    while (res.next()) {
                        Dosen dos = new Dosen();
                        dos.setNIP(res.getString("NIP"));
                        dos.setAlamat(res.getString("ALAMAT"));
                        dos.setNama(res.getString("PENERIMA"));
                        dosen.add(dos);
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(FrameUtamaSekretariat.class.getName()).log(Level.SEVERE, null, ex);
                }
                JFrame fr = new JFrame();
                PanelLihatTabelDosen pan = new PanelLihatTabelDosen(dosen);
                fr.getContentPane().add(pan);
                FormUtil.setMaximize(fr);
                fr.setVisible(true);
            }
        });

        addDosen = new JMenuItem("Tambah Dosen");
        dosen.add(addDosen);

        addDosen.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                FormTambahDosen add = new FormTambahDosen();
            }
        });

        remDosen = new JMenuItem("Hapus Dosen");
        dosen.add(remDosen);
        remDosen.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                FormHapusDosen rem = new FormHapusDosen();
            }
        });

        tabell = new JMenu("TABEL");
        menuBar.add(tabell);

        buatTabel = new JMenuItem("Buat Tabel");
        tabell.add(buatTabel);
        buatTabel.addActionListener(new ActionListener() {
            private String[] args;

            @Override
            public void actionPerformed(ActionEvent e) {
                database.buat_tabel.main(args);
            }
        });

        hapusTabel = new JMenuItem("Hapus Tabel");
        tabell.add(hapusTabel);

        hapusTabel.addActionListener(new ActionListener() {
            private String[] args;

            @Override
            public void actionPerformed(ActionEvent e) {
                database.Hapus_tabel.main(args);
            }
        });
        gambar = new JLabel(new ImageIcon("gambar/welcome.jpg"));
        gambar.setSize(500, 500);
        gambar.setLocation(0, 0);
        gambar.setVisible(true);
        this.getContentPane().add(gambar);
        this.setVisible(true);

    }
}
